package edu.avans.hartigehap.domain;

import java.util.Collection;

public class OrderItemIterator implements CustomIterator
{
	Object[] orderItems;
	int position = 0;
	
	public OrderItemIterator(Collection<OrderItem> orderItems2)
	{
		this.orderItems = orderItems2.toArray();
	}
	
	@Override
	public Object next() {
		OrderItem orderItem = (OrderItem) orderItems[position];
		position = position +1;
		
		return orderItem;
	}
	
	@Override
	public boolean hasNext() {
		//check if the number of items is smaller then the position AND if the next item exists(position set @ next();)
		
		if(position >= orderItems.length || orderItems[position] == null)
		{
			return false;
		}

		return true;
	}

	@Override
	public Object currentItem() {
		OrderItem orderItem = (OrderItem) orderItems[position];

		return orderItem;
	}

	@Override
	public Object first() {
		OrderItem orderItem = (OrderItem) orderItems[0];
		
		return orderItem;
	}

	@Override
	public boolean isDone() {
		
		// If the position is greater than the last or just as large as the last, we are at the end (-:
		
		if(position >= orderItems.length )
			return false;
		else
			return true;
	}

	@Override
	public boolean remove() {
		// TODO Auto-generated method stub
		return false;
	}
}

